package com.lntea.jdbc.spring;

import java.sql.Types;

import javax.sql.DataSource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.SqlUpdate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@ContextConfiguration(locations={"classpath:com/lntea/jdbc/spring/jdbc-template.xml"})
public class SqlUpdateTest {

	@Autowired
	private DataSource ds;

	@Test
	public void testSqlUpdate(){
		GoodsStockSqlUpdate goodsStockUpdate = new GoodsStockSqlUpdate(ds);
		Object[] params = {2L, 1};
		int updateCount = goodsStockUpdate.update(params);
		System.out.println(updateCount);
	}
	
	class GoodsStockSqlUpdate extends SqlUpdate {
		
		public GoodsStockSqlUpdate(DataSource ds) {
			setDataSource(ds);
			setSql("update t_wms_goods_stock set warehouse_id = ? where id = ?");
			setParameters(new SqlParameter(Types.BIGINT), new SqlParameter(Types.INTEGER));
			compile();
		}
		
	}
}
